package com.focus.xyz.core.utils.prop;

import com.focus.xyz.core.utils.ResourceUtil;
import org.apache.commons.lang.StringUtils;

import java.util.Properties;

/**
 * Created by chenmeng on 2016/4/5.
 */
public class ConfigPropInfo {

    private static Properties properties;

    public static String TEST_DATA_DIR = null;
    public static String DRIVER_DIR = null;
    public static String TEST_SRCSHOT_DIR = null;
    public static String TEST_TB_LOGIN_COOKIE_FILE = null;
    public static String TEST_DATA_FILE = null;
    public static String TEST_KEYWORD_FILE = null;
    public static String TEST_UNION_DATA_FILE = null;
    public static String UNION_FRONT_LOGIN_COOKIE_FILE = null;
    public static String UNION_BACK_LOGIN_COOKIE_FILE = null;
    public static String XYZ_BACK_MAIN_URL = null;
    public static String UNION_FRONT_MYUNION_URL = null;
    public static String UNION_DOMAIN = null;

    /*数据库信息*/
    public static String DB_TYPE = null;
    public static String DB_URL = null;
    public static String DB_USERNAME = null;
    public static String DB_PASS = null;

    /*自动录单信息*/
    public static String BABY_CARD_COOKIE_FILE = null;
    public static String BABY_CARD_DATA_FILE = null;

    /*主站*/
    public static String XYZ_FRONT_LOGIN_COOKIE_FILE = null;
    public static String XYZ_DOMAIN = null;

    public static long DRIVER_IMPLICITLY_WAIT = 0;
    public static long DRIVER_EXPLICIT_WAIT = 0;

    /*htmlunit 代理设置*/
    public static String IS_NEED_PROXY = null;
    public static String PROXY_HOST = null;
    public static String PROXY_PORT = null;
    public static String USERNAME = null;
    public static String PASSWORD = null;

    public static String CHROME_BIN = null;
    public static boolean CHROME_PORT_ISFIXED = false;
    public static String CHROME_PORT = null;


    static {
        if(properties == null){
            try{
                properties = ResourceUtil.loadPropertiesFromClassPath("config.properties");
                if(properties == null){
                    throw new Exception("读取文件内容失败");
                }
                TEST_DATA_DIR = properties.getProperty("test.data.dir");
                TEST_SRCSHOT_DIR = properties.getProperty("test.scrshot.dir");
                DRIVER_DIR = properties.getProperty("test.drivers.dir");

                TEST_TB_LOGIN_COOKIE_FILE = properties.getProperty("test.tb.login.cookie.file");
                TEST_DATA_FILE = properties.getProperty("test.data.file");
                TEST_KEYWORD_FILE = properties.getProperty("test.keywork.file");
                TEST_UNION_DATA_FILE = properties.getProperty("test.union.data.file");
                UNION_FRONT_LOGIN_COOKIE_FILE = properties.getProperty("union.front.login.cookie.file");
                XYZ_BACK_MAIN_URL = properties.getProperty("xyz.back.main.url");
                UNION_BACK_LOGIN_COOKIE_FILE = properties.getProperty("union.back.login.cookie.file");
                UNION_FRONT_MYUNION_URL = properties.getProperty("union.front.myunion.url");
                UNION_DOMAIN = properties.getProperty("union.domain");
                /*数据库信息*/
                DB_TYPE = properties.getProperty("db.type");
                DB_URL = properties.getProperty("db.url");
                DB_USERNAME = properties.getProperty("db.username");
                DB_PASS = properties.getProperty("db.pass");

                /*baby card 信息*/
                BABY_CARD_COOKIE_FILE = properties.getProperty("test.tb1.login.cookie.file");
                BABY_CARD_DATA_FILE = properties.getProperty("test.data.file1");

                /*主站*/
                XYZ_FRONT_LOGIN_COOKIE_FILE = properties.getProperty("xyz.front.login.cookie.file");
                XYZ_DOMAIN = properties.getProperty("xyz.domain");

                DRIVER_IMPLICITLY_WAIT = Long.parseLong(properties.getProperty("driver.implicitly.wait"));
                DRIVER_EXPLICIT_WAIT = Long.parseLong(properties.getProperty("driver.explicit.wait"));

                /*htmlunit 代理设置*/
                IS_NEED_PROXY = properties.getProperty("isNeedProxy");
                PROXY_HOST = properties.getProperty("proxyHost");
                PROXY_PORT = properties.getProperty("proxyPort");
                USERNAME = properties.getProperty("username");
                PASSWORD = properties.getProperty("password");

                CHROME_BIN = properties.getProperty("webdriver.chrome.bin");
                CHROME_PORT = properties.getProperty("webdriver.chrome.port");
                CHROME_PORT_ISFIXED = StringUtils.isBlank(CHROME_PORT)?false:true;

            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
